using System;
using System.Collections.Generic;
using System.Text;
using Noein.Math;
using Microsoft.DirectX;
using Noein.Physics;

namespace Noein.Control
{
    //class RigidBodyController : Controller
    //{
    //    private Integrate Integrate = NumericalIntegration.RungeKutta4;
        
    //    private List<Force> forces;

    //    public RigidBodyController()
    //    {
    //        forces = new List<Force>();
    //    }

    //    public override void OnFrameMove(Microsoft.DirectX.Direct3D.Device device, double appTime, float elapsedTime)
    //    {
    //        foreach (Object target in Targets)
    //        {
    //            #region Step 1: compute current position by integrating over previous velocity

                
    //            //Quaternion angularVelocity = 
    //            //    target.PhysicsInfo.QuatAngularVelocity(target.Spatial.Orientation, target.Spatial.OrientationMatrix);
    //            //target.Spatial.Orientation = new Quaternion(
    //            //        Integrate(target.Spatial.Orientation.X, angularVelocity.X, elapsedTime),
    //            //        Integrate(target.Spatial.Orientation.Y, angularVelocity.Y, elapsedTime),
    //            //        Integrate(target.Spatial.Orientation.Z, angularVelocity.Z, elapsedTime),
    //            //        Integrate(target.Spatial.Orientation.W, angularVelocity.W, elapsedTime));
    //            //target.Spatial.Orientation.Normalize();

    //            #endregion
    //        }

    //        foreach (Object target in Targets)
    //        {

    //            #region Step 3: compute the rest current states: force->momentum->velocity

    //            // centripetal a = r * w^2 = w cross (w cross r)
    //            // tangential a = a cross r

    //            // TODO force
    //            //foreach (Force force in forces)
    //            //{
    //            //    force.Apply(Targets.GetRange(index, Targets.Count - index));
    //            //}

    //            // momentum (velocity)
    //            target.Physical.Momentum = new Vector3(
    //                Integrate(target.Physical.Momentum.X, target.Physical.Force.X, elapsedTime),
    //                Integrate(target.Physical.Momentum.Y, target.Physical.Force.Y, elapsedTime),
    //                Integrate(target.Physical.Momentum.Z, target.Physical.Force.Z, elapsedTime));

    //            //target.PhysicsInfo.AngularMomentum = new Vector3(
    //            //    Integrate(target.PhysicsInfo.AngularMomentum.X, target.PhysicsInfo.Torque.X, elapsedTime),
    //            //    Integrate(target.PhysicsInfo.AngularMomentum.Y, target.PhysicsInfo.Torque.Y, elapsedTime),
    //            //    Integrate(target.PhysicsInfo.AngularMomentum.Z, target.PhysicsInfo.Torque.Z, elapsedTime));

    ////            Matrix inverseInertia =
    ////target.PhysicsInfo.InverseWorldMomentOfInertia(target.Spatial.Orientation);
    ////            target.PhysicsInfo.AngularVelocity =
    ////Vector3.TransformCoordinate(target.PhysicsInfo.AngularMomentum, inverseInertia);

    //            #endregion

    //            //index++;
    //        }
    //    }
    //}


}
